package com.example.mushroom.controller;

import com.example.mushroom.entity.AlertLog;
import com.example.mushroom.service.AlertLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/alert-logs")
public class AlertLogController {

    @Autowired
    private AlertLogService alertLogService;

    @PostMapping
    public int insertAlertLog(@RequestBody AlertLog alertLog) {
        return alertLogService.insertAlertLog(alertLog);
    }

    @GetMapping("/{id}")
    public AlertLog selectAlertLogById(@PathVariable Integer id) {
        return alertLogService.selectAlertLogById(id);
    }

    @GetMapping
    public List<AlertLog> selectAllAlertLogs() {
        return alertLogService.selectAllAlertLogs();
    }

    @PutMapping
    public int updateAlertLog(@RequestBody AlertLog alertLog) {
        return alertLogService.updateAlertLog(alertLog);
    }

    @DeleteMapping("/{id}")
    public int deleteAlertLogById(@PathVariable Integer id) {
        return alertLogService.deleteAlertLogById(id);
    }

    @GetMapping("/page")
    public List<AlertLog> selectAlertLogsByPage(@RequestParam int offset, @RequestParam int limit) {
        return alertLogService.selectAlertLogsByPage(offset, limit);
    }
}